import { d as defineComponent, s as storeToRefs, r as ref, k as onMounted, o as openBlock, c as createElementBlock, f as createBaseVNode, b as createVNode, w as withCtx, m as withKeys, a as resolveComponent, h as unref, i as createTextVNode, E as ElMessage, n as search_default } from "./index-NZguwuNX.js";
import { u as useCounterStore, h as http } from "./index-F6B3vg3q.js";
const _hoisted_1 = { class: "df jc-sb title-btn" };
const _hoisted_2 = /* @__PURE__ */ createBaseVNode("span", null, null, -1);
const _hoisted_3 = { class: "dialog-footer" };
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "shopCode",
  setup(__props) {
    const store = useCounterStore();
    const { userInfo } = storeToRefs(store);
    const tableData = ref([]);
    const dialogVisible = ref(false);
    const shop_code_into = async () => {
      dialogVisible.value = true;
    };
    const enter = () => {
    };
    const shop_code_edit = (row) => {
      console.log(row);
    };
    const shop_code_del = async (row) => {
      console.log(row);
      const res = await operate_sql(`DELETE FROM goodcard WHERE GoodCardID = '${row.GoodCardID}'`, "userglobal");
      console.log(res);
      if (res.packageContent.packageMsg == "成功" && res.packageContent.packageStatus === 0) {
        ElMessage.success("删除成功");
        await get_list();
      } else {
        ElMessage.error("删除失败");
      }
    };
    const search_inp = ref("");
    const search_click = async () => {
      let sql = `SELECT goodcard.*, owneruser.BarName FROM goodcard LEFT JOIN owneruser ON goodcard.OwnerUserName = owneruser.OwnerUserName 
WHERE     goodcard.GoodsID LIKE '%${search_inp.value}%'  -- 模糊查询goodcard.id  
      OR goodcard.IDCard LIKE '%${search_inp.value}%'  -- 模糊查询goodcard.name  
      OR goodcard.GoodCardID LIKE '%${search_inp.value}%'  -- 模糊查询goodcard.name  
      OR owneruser.BarName LIKE '%${search_inp.value}%'  -- 模糊查询owneruser.BarName  
ORDER BY   
    goodcard.GoodCardID,     
    CASE WHEN goodcard.OwnerUserName IS NULL AND owneruser.OwnerUserName IS NULL THEN 1 ELSE 0 END    
LIMIT 15 OFFSET 0;`;
      if (search_inp.value == "") {
        tableData.value = await operate_sql(
          `SELECT goodcard.*,owneruser.BarName FROM goodcard LEFT JOIN owneruser ON goodcard.OwnerUserName = owneruser.OwnerUserName ORDER BY goodcard.GoodCardID OR (goodcard.OwnerUserName IS NULL AND owneruser.OwnerUserName IS NULL) LIMIT 15 OFFSET 0`,
          "userglobal"
        );
      } else
        tableData.value = await operate_sql(sql, "userglobal");
    };
    onMounted(async () => {
      await get_list();
    });
    const get_list = async () => {
      tableData.value = await operate_sql(
        `SELECT goodcard.*,owneruser.BarName FROM goodcard LEFT JOIN owneruser ON goodcard.OwnerUserName = owneruser.OwnerUserName ORDER BY goodcard.GoodCardID OR (goodcard.OwnerUserName IS NULL AND owneruser.OwnerUserName IS NULL) LIMIT 15 OFFSET 0`,
        "userglobal"
      );
    };
    const operate_sql = async (sql, name) => {
      const res = await http.corsApi("/index", "post", {
        packID: "123456",
        packageType: "adminSql",
        packageContent: {
          AgentUserName: userInfo.value.username,
          AgentUserPassword: userInfo.value.password,
          sql,
          dbName: name
        }
      });
      console.log(res);
      let data = [];
      if (res.packageContent.packageMsg == "成功") {
        data = res;
      } else {
        data = JSON.parse(res.packageContent.packageMsg);
      }
      console.log(data);
      return data;
    };
    return (_ctx, _cache) => {
      const _component_el_button = resolveComponent("el-button");
      const _component_el_input = resolveComponent("el-input");
      const _component_el_table_column = resolveComponent("el-table-column");
      const _component_el_popconfirm = resolveComponent("el-popconfirm");
      const _component_el_table = resolveComponent("el-table");
      const _component_el_dialog = resolveComponent("el-dialog");
      return openBlock(), createElementBlock("div", null, [
        createBaseVNode("div", _hoisted_1, [
          createBaseVNode("div", null, [
            createVNode(_component_el_input, {
              modelValue: search_inp.value,
              "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => search_inp.value = $event),
              onKeydown: withKeys(search_click, ["enter"]),
              placeholder: "输入任意字段进行模糊查询",
              class: "input-with-select"
            }, {
              append: withCtx(() => [
                createVNode(_component_el_button, {
                  onClick: search_click,
                  icon: unref(search_default)
                }, null, 8, ["icon"])
              ]),
              _: 1
            }, 8, ["modelValue"])
          ]),
          createVNode(_component_el_button, {
            type: "primary",
            onClick: shop_code_into
          }, {
            default: withCtx(() => [
              createTextVNode("添加商品码")
            ]),
            _: 1
          })
        ]),
        createVNode(_component_el_table, {
          border: "",
          data: tableData.value,
          style: { "width": "100%", "margin-top": "15px" }
        }, {
          default: withCtx(() => [
            createVNode(_component_el_table_column, {
              prop: "GoodsID",
              label: "商品ID",
              width: "80"
            }),
            createTextVNode(". "),
            createVNode(_component_el_table_column, {
              prop: "GoodCardID",
              label: "商品码",
              width: "120"
            }),
            createVNode(_component_el_table_column, {
              prop: "IDCard",
              label: "身份证号",
              width: "180"
            }),
            createVNode(_component_el_table_column, {
              prop: "GoodsMoney",
              label: "价格",
              width: "80"
            }),
            createVNode(_component_el_table_column, {
              prop: "GoodsCreateTime",
              label: "创建时间",
              width: "180"
            }),
            createVNode(_component_el_table_column, {
              prop: "GoodsUseTime",
              label: "使用时间",
              width: "180"
            }),
            createVNode(_component_el_table_column, {
              prop: "BarName",
              label: "兑换网吧名称"
            }),
            createVNode(_component_el_table_column, {
              prop: "AgentUserName",
              label: "兑代理用户名"
            }),
            createVNode(_component_el_table_column, {
              prop: "",
              label: "操作",
              width: "180"
            }, {
              default: withCtx((scope) => [
                createVNode(_component_el_button, {
                  onClick: ($event) => shop_code_edit(scope.row)
                }, {
                  default: withCtx(() => [
                    createTextVNode("修改")
                  ]),
                  _: 2
                }, 1032, ["onClick"]),
                createVNode(_component_el_popconfirm, {
                  title: "不在考虑一下?",
                  "confirm-button-text": "确定",
                  "cancel-button-text": "取消",
                  onConfirm: ($event) => shop_code_del(scope.row)
                }, {
                  reference: withCtx(() => [
                    createVNode(_component_el_button, null, {
                      default: withCtx(() => [
                        createTextVNode("删除")
                      ]),
                      _: 1
                    })
                  ]),
                  _: 2
                }, 1032, ["onConfirm"])
              ]),
              _: 1
            })
          ]),
          _: 1
        }, 8, ["data"]),
        createVNode(_component_el_dialog, {
          modelValue: dialogVisible.value,
          "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => dialogVisible.value = $event),
          title: "提示",
          width: "40%"
        }, {
          footer: withCtx(() => [
            createBaseVNode("span", _hoisted_3, [
              createVNode(_component_el_button, {
                onClick: _cache[1] || (_cache[1] = ($event) => dialogVisible.value = false)
              }, {
                default: withCtx(() => [
                  createTextVNode("取消")
                ]),
                _: 1
              }),
              createVNode(_component_el_button, {
                type: "primary",
                onClick: enter
              }, {
                default: withCtx(() => [
                  createTextVNode(" 确认 ")
                ]),
                _: 1
              })
            ])
          ]),
          default: withCtx(() => [
            _hoisted_2
          ]),
          _: 1
        }, 8, ["modelValue"])
      ]);
    };
  }
});
export {
  _sfc_main as default
};
